import { ElMessage } from "element-plus";
import { messageErrorTip } from "@/utils/message-config";
import { AxiosError, AxiosResponse } from "axios";

/**
 * @description: 校验网络请求状态码
 * @param {Number} status
 * @return void
 */
export const checkStatus = (error: AxiosError) => {
  let response: AxiosResponse | undefined = error?.response;
  let status: number | undefined = error?.response?.status;
  switch (status) {
    case 400:
      messageErrorTip("请求失败！请您稍后重试");
      break;
    // case 401:
    //   messageErrorTip("登录失效！请您重新登录");
    //   break;
    case 403:
      messageErrorTip("当前账号无权限访问！");
      break;
    case 404:
      // messageErrorTip("你所访问的资源不存在！");
      messageErrorTip("接口未找到：" + response?.data.path);
      break;
    case 405:
      messageErrorTip("请求方式错误！请您稍后重试");
      break;
    case 408:
      messageErrorTip("请求超时！请您稍后重试");
      break;
    case 500:
      messageErrorTip("服务器异常：" + response?.data.message || "系统内部异常");
      break;
    case 502:
      messageErrorTip("网关错误！");
      break;
    case 503:
      messageErrorTip("服务不可用！");
      break;
    case 504:
      messageErrorTip("网关超时！");
      break;
    default:
      messageErrorTip("请求失败！");
  }
};
